<?php

namespace app\admin\logic\zhxy;

use app\admin\logic\ZHXY;
use app\admin\model\Flow;
use app\admin\model\WfRunProcess;

trait WorkFlow
{


    /**
     * @var Flow $flow_row
     */
    public $flow_row;

    public $flowTable;
    /**
     * @var WfRunProcess $current_process
     */
    public $current_process;

    /**
     * @var WfRunProcess $current_process
     */
    public $next_process;


    /**
     *
     * @var WfRunProcess[] $all_process
     */
    private $all_process;

    public $current_hook;

    /**
     * 设置 流程数据
     *
     * @param $flow_row
     * @param $flowTable
     * @return self
     */
    public function setFlow($flow_row, $flowTable)
    {
        $this->flow_row  = $flow_row;
        $this->flowTable = $flowTable;

        return $this;
    }


    /**
     * 设置 当前 进度
     *
     * @param $c
     * @return $this
     */
    public function setCurrentProcess(&$c)
    {
        $this->current_process = $c;
        $masterPor             = \app\admin\logic\workflow\WfRunProcess::getMasterProsess($c);

        if (!$masterPor->application_id) {
            $masterPor->application_id = ZHXY::unid();
            $masterPor->save();
        }


        return $this;
    }

    /**
     * 设置当前 hook
     *
     * @param $hook
     * @return $this
     */
    public function setCurrentHook($hook)
    {
        $this->current_hook = $hook;

        return $this;
    }

    /**
     * 获取当前的进度
     *
     * @return WfRunProcess
     */
    public function getCurrentProcess()
    {
        return $this->current_process;
    }

    /**
     * 获取全部流程信息
     *
     * @return WfRunProcess[]|bool
     */
    public function getAllProcess()
    {
        if (!$this->all_process) {
            $this->all_process = \app\admin\logic\workflow\WfRunProcess::getAllProsess($this->current_process);
        }

        return $this->all_process;
    }

}